import maya.cmds as mc
#import LZ_correctCurrentShape
#reload(LZ_correctCurrentShape)


import tools_Persional.LZ_Tools.LZ_Tools.correctCurrentShape.shapeCorrect
reload(tools_Persional.LZ_Tools.LZ_Tools.correctCurrentShape.shapeCorrect)
#shapeCorrect.cort.correctiveShapeCmd()

import tools_Persional.LZ_Tools.LZ_Tools.LZ_mirrior_BlendShape
reload(tools_Persional.LZ_Tools.LZ_Tools.LZ_mirrior_BlendShape)


import    tools_Persional.LZ_Tools.LZ_Tools.LZ_wrapDeformer as LZ_wrapDeformer
reload(LZ_wrapDeformer)


class blendshape_menege(tools_Persional.LZ_Tools.LZ_Tools.correctCurrentShape.shapeCorrect.ShapeCorrect,
                        tools_Persional.LZ_Tools.LZ_Tools.LZ_mirrior_BlendShape.LZ_mirrior_BlendShape,
                        LZ_wrapDeformer.LZ_wrapBlend
                        ):

    def blendshape_menege_UI(self):
        blendshape_menege_UI = 'blendshape_menege_UI'
        if mc.window(blendshape_menege_UI,ex = True):
            mc.deleteUI(blendshape_menege_UI)
            
        mc.window(blendshape_menege_UI,widthHeight=(400, 250),t='LZ_blendshape_menege_UI_v1.01_2014/04/16',menuBar = True,rtf=True,s=True)
        mc.columnLayout('main_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=400 )
        
        mc.columnLayout('ObjLoad_collayout',columnAttach=('both', 1), rowSpacing=10, columnWidth=390 )
        mc.rowLayout('ObjLoad_rowLY',numberOfColumns=4, columnWidth4=(60,150,40,150), adjustableColumn=4, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0), (4, 'both', 0)] )
        
        mc.button('loadObj',c=lambda *args:self.loadObj2List01())
        mc.textField('ObjSelLoadTF',ed=False)
        mc.text('-->>')
        mc.textField('blenshapeName',ed=False)
        
        mc.setParent('main_layout')
        mc.rowLayout('blendList_rowLY',numberOfColumns=2, columnWidth2=(240, 160), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0)] )
        
        mc.textScrollList('blendShapeList',allowMultiSelection=True, height =  155,width = 95,dcc=lambda *args:self.selectConnectedObj(),sc=lambda *args:self.showCurrentNodeInfo())
        mc.popupMenu(mm=True)
        mc.menuItem('AppendTarget_menu',l ="Append",rp= "N",c=lambda *args:self.AppendTarget())
        mc.menuItem('RemoveTarget_menu',l= "Remove",rp ="S",c=lambda *args:self.RemoveTarget())
        mc.menuItem( 'ReplaceTarget_menu',l="Replace",rp ="W",c= lambda *args:self.ReplaceTarget())
        mc.menuItem('RenameTarget_menu',l= "Rename",rp ="E",c=lambda *args:self.renameTargetWin())
        mc.menuItem('ReBuild_Target_menu',l= "ReBuild_Target",rp ="NE",c=lambda *args:self.Rebuild_Target())
        mc.menuItem('normalize_Target_menu',l= "normalize_Target",rp ="NW",c=lambda *args:self.normalize_Target())

        
        
        
        mc.columnLayout('blendshapeMenage_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=150 )
        
        mc.text('->> blend_Batch_menage <<-')
        mc.button('Got_BlendShapeTarget',h=30)
        mc.button('normalize_BlendShapeName',h=30,c=lambda *args:self.normalize_Target_All())
        mc.button('select_All_Target',h=30,c=lambda *args:self.select_All_Target())
        
        mc.setParent('main_layout')
        
        mc.columnLayout('currentBlendWeightList_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=390 )
        mc.textField('currentBlendWeightList',w=390,ed=False)
        
        mc.button('create  correct shape ',h=30,c=lambda *args:self.correctiveShapeCmd())
        mc.button('Mirror shape Window ',h=30,c=lambda *args:self.LZ_MirrorShapesWindow())
        mc.button('replace connection Window ',h=30,c=lambda *args:self.LZ_WrapDeformer_UI())
        
        mc.window(blendshape_menege_UI,e=True,widthHeight=(400, 360))
        mc.showWindow()
    
    
    

    
    #==================================================================================================================
    #------------------------------------------------------------------------------------------------------------------
    def normalize_Target_All(self):
        OriMesh=mc.textField('ObjSelLoadTF',q=True,text=True)
        blendShapeNode=mc.textField('blenshapeName',q=True,text=True)
        OriWeight=mc.textScrollList('blendShapeList',q=True,allItems=True)
        
        self.normalize_Target_Command(OriMesh,blendShapeNode,OriWeight)
    def normalize_Target(self):
        OriMesh=mc.textField('ObjSelLoadTF',q=True,text=True)
        blendShapeNode=mc.textField('blenshapeName',q=True,text=True)
        OriWeight=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        self.normalize_Target_Command(OriMesh,blendShapeNode,OriWeight)
    '''
    normalize_Target_Command('XXX','XXXX',[])
    '''
    def normalize_Target_Command(self,OriMesh,blendShapeNode,OriWeight):

        errorTarget=[]
        Non_Unique=[]
        finishMesh=[]
        
        for ow in OriWeight:
            connectObj=self.selectConectInputObj(blendShapeNode,ow)
            if connectObj==ow:
                pass
            else:
             
                if connectObj=='':
                    errorTarget.append(ow)
                    
                else:
                    if '|' in connectObj:
                        Non_Unique.append(connectObj)
                    else:
                        
                        self.renameTargetWeightName(connectObj,blendShapeNode,ow)
                        finishMesh.append(connectObj)
                
                
        if finishMesh==[]:
            finishMeshText=''
        else:
            finishMeshText=str(finishMesh)+' has finished   '
        
        if errorTarget==[]:
            errorTargetText=''
        else:
            errorTargetText=str(errorTarget)+' has missing Target Mesh   '
            
        if Non_Unique==[]:
            Non_UniqueText=''
        else:
            Non_UniqueText=str(Non_Unique)+' has Non Unique name in scene'

        mc.select(OriMesh)
        self.loadObj2List01()
        mc.textScrollList('blendShapeList',e=True,selectItem=finishMesh)
        mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text=finishMeshText+errorTargetText+Non_UniqueText)
        
    def Rebuild_Target(self):
        OriMesh=mc.textField('ObjSelLoadTF',q=True,text=True)
        blendShapeNode=mc.textField('blenshapeName',q=True,text=True)
        getWeightName=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        
        FailObj=[]
        failInfo=0
        for target in getWeightName:
            objsource=self.selectConectInputObj(blendShapeNode,target)
            if mc.objExists(target)==1 or objsource!=0:
                FailObj.append(target)
                failInfo=failInfo+1
        
        if failInfo==0:
            for target in getWeightName:
                self.getTargetInputMesh(OriMesh,blendShapeNode,target)
                mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text='rebuild Target Successed')
        else:
            mc.textField('currentBlendWeightList',e=True,bgc=[0.9,0,0],text='the target of '+str(FailObj)+' has already existed in current secne ')
    
    def select_All_Target(self):
        AllTarget=self.listAllTarget()
        blendShapeNode=mc.textField('blenshapeName',q=True,text=True)
        sourceObjInput=[]
        failInput=[]
        for at in AllTarget:
            objInput=self.selectConectInputObj(blendShapeNode,at)
            #print(objInput)
            if mc.objExists(objInput) == 1:
                sourceObjInput.append(objInput)
            else:
                failInput.append(at)
        #print(sourceObjInput)
        mc.select(sourceObjInput)
        
        listInfo=str(sourceObjInput)+' has selected,   '+str(failInput)+' missed target'
        if failInput==[]:
            colorGetBack=[0,0.65,0]
        else:
            colorGetBack=[0.9,0,0.5]
        
        mc.textField('currentBlendWeightList',e=True,bgc=colorGetBack,text=listInfo)
    
    
    def selectConnectedObj(self):
        blendShapeNode=mc.textField('blenshapeName',q=True,text=True)
        getWeightName=mc.textScrollList('blendShapeList',q=True,selectItem=True)[0]

        objsource=self.selectConectInputObj(blendShapeNode,getWeightName)
        
        if objsource !=0:
            mc.select(objsource)
            mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text='selected '+str(objsource))
        else:
            mc.textField('currentBlendWeightList',e=True,bgc=[0.9,0,0],text='the source blendShape target has missed ')
    
    def AppendTarget(self):
        seleObject=mc.ls(sl=True)
        textResult01=''
        textResult02=''
        textResult=''
        if seleObject==None:
            pass
        else:
            BaseMesh=mc.textField('ObjSelLoadTF',q=True,text=True)
            feedback01=1
            feedback02=1
            blendshapeNode=mc.textField('blenshapeName',q=True,text=True)
            for so in seleObject:

                if so in self.listAllTarget():
                    textResult02='there is some meshs has already existed in '+str(blendshapeNode)
                    feedback02=0
                
                    
                        
                else:
                    if so!=BaseMesh:

                        lastIndex=self.findLastIndex(blendshapeNode)

                        mc.blendShape(blendshapeNode,e=True,tc=True,t=[BaseMesh,lastIndex,so,1])
                        
                        self.refreshList(blendshapeNode)
                        
                    else:
                        
                        #mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text='please select one mesh which name is not '+str(BaseMesh)+' at last')
                        feedback01=0
                        mc.select(so)
                        pass 
            if feedback01==1:
                
                if feedback02==1:
                    textResult=str(seleObject)+'has appended to the '+str(blendshapeNode)+str(lastIndex)
                    backGroundColor=[0,0.65,0]
                else:
                    textResult=textResult01 + textResult02 + ',the others continued'
                    backGroundColor=[0.9,0,0.5]
            else:
                textResult01='there is a mesh selected named '+str(BaseMesh)
                textResult=textResult01 + textResult02 + ',the others continued'
                backGroundColor=[0.9,0,0.5]


            mc.textField('currentBlendWeightList',e=True,bgc=backGroundColor,text=textResult)
    def refreshWinShow(self):
        mc.button('rename_Targets',e=True,en=False)
        self.refreshUI()
    
    def refreshUI(self):
        child_LYs=mc.columnLayout('renameTargetWinmain_layout',q=True, ca=True )
        blendshape=mc.textField('blenshapeName',q=True,text=True)
        for cdl in child_LYs:
            
            RL_Mems = mc.rowLayout(cdl,q=True, ca=True )
            OriWeight=mc.textField(RL_Mems[1],q=True,text=True)
            newNameWeight=mc.textField(RL_Mems[0],q=True,text=True)
            
            mc.textField(RL_Mems[0],e=True,text=OriWeight)
            mc.textField(RL_Mems[1],e=True,ed=True)
            mc.textField(RL_Mems[1],e=True,bgc=[0,0,0])
            
            
        mc.button('rename_Targets',e=True,en=True)
    def ReplaceTarget(self):
        objsel=mc.ls(sl=True)
        OriWeight=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        
        if len(OriWeight)==len(objsel):
            print(len(objsel))
            for num in range(len(objsel)):
                print(objsel[num],OriWeight[num])
                self.RebuildTarget(objsel[num],OriWeight[num])
            mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text=' finish replaced   ')
        else:
            mc.textField('currentBlendWeightList',e=True,bgc=[0.9,0,0],text=' the count of selected is not equal the count of list ')
    def RebuildTarget(self,TargetMesh,target):
        #newNameWeight='blendshapeNeedDelete_target'
        blendshape=mc.textField('blenshapeName',q=True,text=True)

        #OriWeight=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        OriMesh=mc.textField('ObjSelLoadTF',q=True,text=True)

        #for target in OriWeight:

        TargetIndex=self.getWeightIndex(blendshape,target)
        print(OriMesh,TargetMesh,TargetIndex,TargetIndex)
        self.RebuildTargetConnect(OriMesh,TargetMesh,blendshape,TargetIndex)
            
    #def RebuildTargetConnect(self,OriMesh,TargetMesh,blendshapeNode,TargetIndex):
    #    getOriMeshShapes=mc.listRelatives(OriMesh,s=True)
    #    getTargetMeshShapes=mc.listRelatives(TargetMesh,s=True)
    #    if len(getOriMeshShapes)==len(getTargetMeshShapes):
    #        for i in range(len(getOriMeshShapes)):
    #        
    #            inputTargetNum=TargetIndex-1
    #            InputTargetItemNum=self.getTargetInputTargetItem(blendShapeNode,inputTargetNum)
    #            connecteAttr=str(blendShapeNode)+'.inputTarget['+str(i)+'].inputTargetGroup['+str(inputTargetNum)+'].inputTargetItem['+str(InputTargetItemNum[0])+'].inputGeomTarget'
    #            sourceInput=str(getTargetMeshShapes)+'.worldMesh[0]'
    #            mc.connectAttr(sourceInput,connecteAttr)
    #            
                    
        
        
    def renameTarget(self):
        child_LYs=mc.columnLayout('renameTargetWinmain_layout',q=True, ca=True )
        blendshape=mc.textField('blenshapeName',q=True,text=True)
        for cdl in child_LYs:
            
            RL_Mems = mc.rowLayout(cdl,q=True, ca=True )
            OriWeight=mc.textField(RL_Mems[0],q=True,text=True)
            newNameWeight=mc.textField(RL_Mems[1],q=True,text=True)
            mc.textField(RL_Mems[1],e=True,ed=False)
            mc.textField(RL_Mems[1],e=True,bgc=[0,0.65,0])
            

            self.renameTargetWeightName(newNameWeight,blendshape,OriWeight)
            
        self.refreshList(blendshape)
            
        mc.button('rename_Targets',e=True,en=False)
        mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text=' finish renamed  ')
    def renameTargetWin(self):
        renameTargetWin = 'renameTargetWin'
        if mc.window(renameTargetWin,ex = True):
            mc.deleteUI(renameTargetWin)
            
        mc.window(renameTargetWin,widthHeight=(300, 300),t='renameTargetWin',menuBar = True,rtf=True,s=True)
        mc.columnLayout('renameTarget_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=300 )
        mc.columnLayout('renameTargetWinmain_layout',columnAttach=('both', 1), rowSpacing=10, columnWidth=300 )
        #mc.rowLayout('renameTargetWinmain_rowLY',numberOfColumns=2, columnWidth2=(100,100), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0)] )
        targetAll=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        for ta in targetAll:
            mc.setParent('renameTargetWinmain_layout')
            mc.rowLayout(ta+'_rowLY',parent='renameTargetWinmain_layout',numberOfColumns=2, columnWidth2=(150,150), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0)] )

            mc.textField(ta+'_TF',text=ta,ed=False)
            mc.textField(ta+'_RN',text='')
        mc.setParent('renameTarget_layout')
        mc.button('rename_Targets',c=lambda *args:self.renameTarget())
        mc.button('refresh_UI_show',c=lambda *args:self.refreshWinShow())
        
        
        
        mc.window(renameTargetWin,e=True,widthHeight=(300, 300))
        mc.showWindow(renameTargetWin)
    def RemoveTarget(self):
        ##BaseMesh=mc.textField('ObjSelLoadTF',q=True,text=True)
        ##blendshapeNode=mc.textField('blenshapeName',q=True,text=True)
        ##blendshape=mc.textField('blenshapeName',q=True,text=True)
        ##getWeightNames=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        ##if mc.textScrollList('blendShapeList',q=True,numberOfSelectedItems=True)!=0:
        ##    for gen in getWeightNames:
        ##        getWeightInedex=self.getWeightIndex(blendshape,gen)
        ##        mc.blendShape(blendshapeNode,e=True,rm=True,t=[BaseMesh,getWeightInedex,gen,1])        ##        self.refreshList(blendshapeNode)
        ##else:
        ##    mc.textField('currentBlendWeightList',e=True,bgc=[0.9,0,0],text='there is no target is selected ,one target at last is selected in textScrollList')
        newNameWeight='blendshapeNeedDelete_targetTemple'
        blendshape=mc.textField('blenshapeName',q=True,text=True)
        OriWeight=mc.textScrollList('blendShapeList',q=True,selectItem=True)
        OriMesh=mc.textField('ObjSelLoadTF',q=True,text=True)
        print(OriWeight)
        for ow in OriWeight:
        
            getWeightInedex=self.getWeightIndex(blendshape,ow)
            print(getWeightInedex)
            self.renameTargetWeightName(newNameWeight,blendshape,ow)
            
                        mc.duplicate(OriMesh,n=newNameWeight)

            self.refreshList(blendshape)
            

            self.RebuildTarget(newNameWeight,newNameWeight)
            mc.blendShape(blendshape,e=True,rm=True,t=[OriMesh,getWeightInedex,newNameWeight,1])
            
            mc.delete(newNameWeight)
            self.refreshList(blendshape)
            
        
        mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text=str(OriWeight)+' has removed from '+blendshape)
    
    def refreshList(self,blendshapeNode):
        targetName=self.getWeightName(blendshapeNode)
        selectedII=mc.textScrollList('blendShapeList',q=True,selectIndexedItem=True)
        mc.textScrollList('blendShapeList',e=True, ra=True)

        for tn in targetName:
            mc.textScrollList('blendShapeList',e=True, a =tn)
        if selectedII!=None:  
            mc.textScrollList('blendShapeList',e=True,selectIndexedItem=selectedII[0])
    def showCurrentNodeInfo(self):
        blendshape=mc.textField('blenshapeName',q=True,text=True)
        getWeightName=mc.textScrollList('blendShapeList',q=True,selectItem=True)[0]
        getWeightInedex=self.getWeightIndex(blendshape,getWeightName)
        
        mc.textField('currentBlendWeightList',e=True,bgc=[0.9,0.9,0.3],text='Weight name :  '+ blendshape + ' ;' + 'Weight Index : '+ str(getWeightInedex))
    def loadObj2List01(self):
        objsel=mc.ls(sl=True)[0]
        mc.textField('ObjSelLoadTF',e=True,text=objsel)
        blendshapeNode=self.getBlendshapeNode()
        if blendshapeNode==None:
            mc.textField('currentBlendWeightList',e=True,bgc=[0.9,0,0],text='the object selected has no a node which type is "blendShape"')
        else:
            mc.textField('blenshapeName',e=True,text=blendshapeNode)
        
            targetName=self.getWeightName(blendshapeNode)
        
            mc.textScrollList('blendShapeList',e=True, ra=True)
        
            for tn in targetName:
                mc.textScrollList('blendShapeList',e=True, a =tn)
            mc.textField('currentBlendWeightList',e=True,bgc=[0,0.65,0],text=' the first blendShape is '+str(blendshapeNode))
    
    def listAllIndex(self):
        getWeightName=mc.textScrollList('blendShapeList',q=True,allItems=True)
        blendshapeNode=self.getBlendshapeNode()
        IndexAll=[]
        for gen in getWeightName:
            Index=self.getWeightIndex(blendShapeNode,gen)
            IndexAll.append(Index)
        return IndexAll
    def listAllTarget(self):
        
        blendshapeNode=mc.textField('blenshapeName',q=True,text=True)
        getWeightName=self.getWeightName(blendshapeNode)
        
        return getWeightName

    #------------------------------------------------------------------------------------------------------------------
    '''
    getTargetInputTargetItem ( string , int )
    
    get the value like 6000    get (int)
    '''
    def getTargetInputTargetItem(self,blendShapeNode,inputTargetNum):
        InputTargetItem=mc.getAttr(str(blendShapeNode)+'.inputTarget[0].inputTargetGroup['+str(inputTargetNum)+'].inputTargetItem' ,mi=True)
        return InputTargetItem
    '''
    getWeightIndex(string,string)
    get the index of the weight input    get (int)
    
    ''' 
    def getWeightIndex(self,blendShapeNode,target):
        aliases=mc.aliasAttr(blendShapeNode,q=True)

        for i in range(len(aliases)):
            if target==aliases[i]:
                index=(aliases[i+1].split('[')[1]).split(']')[0]
                
                index=int(index)+1
                break
            else:
                index='something mistake has Occurred'

        return index
    '''
    getWeightName(string)
    get the weight names in the blendShape input
    
    '''
    def getWeightName(self,blendShapeNode):
        aliases=mc.aliasAttr(blendShapeNode,q=True)
        blendshapeTarget=[]
        for bt in range(len(aliases)/2):
            blendshapeTarget.append(aliases[bt*2])
        return(blendshapeTarget)
        
    def findLastIndex(self,blendShapeNode):
        aliases=mc.aliasAttr(blendShapeNode,q=True)
        index=1
        for i in range(len(aliases)/2):
            currentIndex=int((aliases[i*2+1].split('[')[1]).split(']')[0])+1
            if currentIndex>index:
                index=currentIndex
        return(index)
        #i =len(aliases)/2-1
        #index=int((aliases[i*2+1].split('[')[1]).split(']')[0])+1
        #return(int(index))
        #
    def getBlendshapeNode(self):
        blendNode=''
        for leave in range(6):
            
        
            nodeHistory=mc.listHistory(lv=leave+1)

            for i in nodeHistory:
                print (i)
                if mc.nodeType(i)=='blendShape':
                    blendNode=i
            if blendNode!='':
                break
        return(blendNode)
    def renameTargetWeightName(self,newName,blendshapenode,targetWeight):
        
        mc.aliasAttr(newName,str(blendshapenode)+'.'+str(targetWeight))
    
    '''
    
    RebuildTargetConnect(string,string,string,int)
    
    reconnect the target and blendShape weight
    
    '''
    def RebuildTargetConnect(self,OriMesh,TargetMesh,blendshape,TargetIndex):

        getOriMeshShapes=mc.listRelatives(OriMesh,s=True)
        getTargetMeshShapes=mc.listRelatives(TargetMesh,s=True)

        for gom in getOriMeshShapes:
            if 'Orig' in gom:
                getOriMeshShapes.remove(gom)
                
        for gtm in getTargetMeshShapes:
            if 'Orig' in gtm:
            
                getTargetMeshShapes.remove(gtm)
            
        if len(getOriMeshShapes)==len(getTargetMeshShapes):

            for i in range(len(getOriMeshShapes)):
                if 'Orig' in getTargetMeshShapes[i]:
                    pass
                else:
                    inputTargetNum=int(TargetIndex)-1
                    InputTargetItemNum=self.getTargetInputTargetItem(blendshape,inputTargetNum)
                    connecteAttr=str(blendshape)+'.inputTarget['+str(i)+'].inputTargetGroup['+str(inputTargetNum)+'].inputTargetItem['+str(InputTargetItemNum[0])+'].inputGeomTarget'
                    sourceInput=str(getTargetMeshShapes[i])+'.worldMesh[0]'
                    
                    sourceMesh=mc.listConnections(connecteAttr,s=True)
                    if sourceMesh!=None:
                        sourceMeshShapes=mc.listRelatives(sourceMesh,s=True)
                        mc.disconnectAttr(str(sourceMeshShapes[i])+'.worldMesh[0]', connecteAttr)

                    mc.connectAttr(sourceInput,connecteAttr)
                    
    '''
    selectConectInputObj(string,sting)
    select the object which is the target of blendShape

    ''' 
    def selectConectInputObj(self,blendShapeNode,getWeightName):
        inputTargetNum=self.getWeightIndex(blendShapeNode,getWeightName)-1
        InputTargetItemNum=self.getTargetInputTargetItem(blendShapeNode,inputTargetNum)

        conneSouce=mc.listConnections(str(blendShapeNode)+'.inputTarget[0].inputTargetGroup['+str(inputTargetNum)+'].inputTargetItem['+str(InputTargetItemNum[0])+'].inputGeomTarget',s=True)
        if conneSouce!=None:
            return conneSouce[0]
            
        else:
            return 0
            
    def setAllTargetWeight2Off(self,blendshape):
        AllTargets=self.getWeightName(blendshape)
        for at in AllTargets:
            mc.setAttr(str(blendshape)+'.'+str(at),0)
    def setTargetWeight2On(self,blendshape,target):
        mc.setAttr(str(blendshape)+'.'+str(target),1)
    def getTargetInputMesh(self,OriMesh,blendshape,target):
        self.setAllTargetWeight2Off(blendshape)
        self.setTargetWeight2On(blendshape,target)
        TargetIndex=self.getWeightIndex(blendshape,target)
        mc.duplicate(OriMesh,n=target)
        
        self.RebuildTargetConnect(OriMesh,target,blendshape,TargetIndex)

        
    
